<?php

use yii\db\Schema;
use yii\db\Migration;

class m160305_110123_add_package_schedule extends Migration
{
    public function up()
    {
        $sql = <<<FINE
CREATE TABLE {{%package_schedule}} (
  id int(11) NOT NULL AUTO_INCREMENT,
  type int(1) NOT NULL DEFAULT '0' COMMENT '0 for all in one, 1 for banner, 2 for banner, 4 for mobile',
  begin timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  end timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  request_ip varchar(15) DEFAULT NULL COMMENT 'UI operate user ip, none for python package ',
  last_update timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (id),
  KEY type (type)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

FINE;
        $this->execute($sql);
        $this->addColumn('{{%adspace}}', 'ad_form', "int(10) NOT NULL DEFAULT '1' COMMENT 'Adspace Form 1 PC Banner, 2 PC Popup, 3 Client, 4 Video Pause' after position ");
        return true;
    }

    public function down()
    {
        $this->dropTable('{{%package_schedule}}');
        $this->addColumn('{{%adspace}}', 'ad_form');
        return true;
    }
}
